#include <iostream>
#include<math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <deque>
#include <random>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <tuple>
#include <thread>
#include <chrono>
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18+1e17;
int bitcount(ll n) { return n == 0 ? 0 : bitcount(n & (n - 1)) + 1;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll binexp(ll a, ll b){
if (!b) return 1;
ll res = binexp(a, b/2);
res = (res*res)%mod;
if(b%2) res = (res*a)%mod;
return res;
}
ll rev(ll x) {return binexp(x, mod - 2);}
vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
int n,m;
cin >> n >> m;
vector<vector<char>> table(n+2, vector<char>(m+2, '#'));
for(int i =1;i<=n;i++){
for(int j=1;j<=m;j++) cin >> table[i][j];
}
vector<vector<int>> dp(n+2, vector<int>(m+2,0));
vector<vector<bool>> used(n+2, vector<bool>(m+2,false));
int start_x, start_y;
for(int i =1;i<=n;i++){
for(int j =1;j<=m;j++){
if(table[i][j]=='.') dp[i][j] = 1;
else if(table[i][j]=='L') {
start_y = i, start_x = j;
dp[i][j] = 2;
}
}
}
queue<pair<int,int>> q;
q.push(make_pair(start_x, start_y));
while(!q.empty()){
auto p = q.front();
q.pop();
//dp[y][x] = A[i][j];
int x = p.first, y = p.second;
for(int i =0;i<4;i++){
int new_x = x+dx[i], new_y = y + dy[i];
if(dp[new_y][new_x]==1 && !used[new_y][new_x]){
int bad = 0, good = 0;
for(int i =0;i<4;i++){
if(dp[new_y+dy[i]][new_x+dx[i]] == 0) bad++;
if(dp[new_y+dy[i]][new_x+dx[i]]==2) good++;
}
if(bad>=2 || (bad==1 && good>=2) || (bad==0 && good>=3)){
used[new_y][new_x] = true;
dp[new_y][new_x] = 2;
table[new_y][new_x] = '+';
q.push(make_pair(new_x, new_y));
}
}
}
}
for(int i =1;i<=n;i++){
for(int j=1;j<=m;j++) cout << table[i][j] << "";
cout << '\n';
}
}
}
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |
238. Product of Array Except Self | 229. Majority Element II |
222. Count Complete Tree Nodes | 215. Kth Largest Element in an Array |
198. House Robber | 153. Find Minimum in Rotated Sorted Array |